package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.ConditionsEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.MultiUnitPricePoJo;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.businessproduct.pojo.dto.BusinessProductListDTO;
import com.xbongbong.pro.detailtab.vo.ProductSummaryVO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainInLinkItemDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.outstock.pojo.dto.OutStockListDTO;
import com.xbongbong.pro.outstock.pojo.dto.OutstockDeleteBatchDTO;
import com.xbongbong.pro.outstock.pojo.dto.OutstockEditAttrUpdateDTO;
import com.xbongbong.pro.outstock.pojo.dto.OutstockUpdateByBusinessRuleDTO;
import com.xbongbong.pro.outstock.pojo.vo.OutStockListVO;
import com.xbongbong.pro.outstock.pojo.vo.OutstockDeleteBatchVO;
import com.xbongbong.pro.outstockproduct.pojo.dto.FormatOutstockProductDTO;
import com.xbongbong.pro.product.pojo.dto.PagingProductDTO;
import com.xbongbong.pro.product.pojo.vo.PagingProductVO;
import com.xbongbong.saas.domain.entity.OutstockProductEntity;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;

import java.util.List;
import java.util.Map;

/**
 * 出库单接口
 *
 * @author chaoxiong.lei
 * @date 19:07 2019/1/20
 * @since v1.0
 **/
public interface OutstockService extends SaasSaveService {
    /**
     * 获取所有出货单金额
     * @param data
     * @param dataId
     * @param contractOutstockListVO
     * @return double
     * @throws XbbException
     * @author xinpeng.jiang
     * @date 2020/12/16 11:27
     * @version 1.0
     */
    double getContractOutstockTotalMoney(JSONObject data, Long dataId, PaasFormDataEsListVO contractOutstockListVO) throws XbbException;

    /**
     * 出库单产品保存
     *
     * @param productArray 产品数组
     * @param corpid       公司id
     * @param outstockId   对应出库单的id
     * @param type
     * @param refId
     * @param formId
     * @param isWorkflow
     * @author lcx
     * @date 2019-02-01 15:19
     */
    void saveProduct(JSONArray productArray, String corpid, Long outstockId, Integer type, Long refId, Long formId, boolean isWorkflow) throws XbbException;

    /**
     * 获取出库单
     *
     * @param outStockListDTO
     * @return com.xbongbong.pro.outstock.pojo.vo.OutStockListVO
     * @throws XbbException 业务异常
     * @author 吴峰
     * @date 2019/3/1 21:27
     */
    OutStockListVO findOutstockList(OutStockListDTO outStockListDTO) throws XbbException;

    /**
     * 按照查询条件查找符合条件的数据从ES中
     *
     * @param corpid 公司ID
     * @param refId  关联单据ID
     * @param type   出库类型 详见OutstockTypeEnum枚举
     * @date 2019/2/27 19:20
     * @author lcx
     * @see com.xbongbong.saas.enums.OutstockTypeEnum;
     */
    PaasFormDataEsListVO getOutstockListFromEs(String corpid, Long refId, Integer type, Integer distributorMark) throws XbbException;


    /**
     * 将出库单产品格式化返回给前端
     *
     * @param formatOutstockProductDTO 格式化出库单产品的DTO
     * @return 一个出库单产品的JSONObject
     * @Date 22:20 2019/3/4
     * @since v1.0
     **/
    JSONObject getFormatProductJsonArray(FormatOutstockProductDTO formatOutstockProductDTO) throws XbbException;

    /**
     * 获取出库单产品
     *
     * @param businessProductListDTO 入参
     * @param jsonObject 数据对象
     * @return 出库单VO，属性product包含了出库单关联产品，返回给前端的格式
     * @author chaoxiong.lei
     * @Date 14:37 2019/3/5
     * @since v1.0
     **/
//    BusinessProductListVO getOutstockProductList(BusinessProductListDTO businessProductListDTO, JSONObject jsonObject) throws XbbException;

    /**
     * 批量删除出库单
     * @author 吴峰
     * @date 2019/3/15 14:34
     * @param outstockDeleteBatchDTO
     * @return com.xbongbong.pro.outstock.pojo.vo.OutstockDeleteBatchVO
     * @throws XbbException 业务异常
     */
    OutstockDeleteBatchVO deleteBatch(OutstockDeleteBatchDTO outstockDeleteBatchDTO) throws XbbException;

    /**
     * 批量某个字段
     * @author 吴峰
     * @date 2019/3/20 14:27
     * @param outstockEditAttrUpdateDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void batchEditAttr(OutstockEditAttrUpdateDTO outstockEditAttrUpdateDTO) throws XbbException;
    /**
     * 关联新建时格式化解释
     * @author 吴峰
     * @date 2019/4/1 21:56
     * @param handlerExplainInLinkItemDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void formatLinkAddExplain(HandlerExplainInLinkItemDTO handlerExplainInLinkItemDTO) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO 导入入参
     * @param titlePojoList     标题
     * @param rowGroupPojo      一个表单对应的一组Excel填写的数据
     * @param fieldAttrList     解释
     * @return FormDataAddDTO
     * @throws XbbException XbbException
     * @author lee
     * @date 2019/4/29 14:16
     * @since V1.0
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 格式化导出值
     *
     * @param paasFormDataESList 数据
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * Description: 出库单 仓库一致性同步
     * @param corpid
     * @param dataId
     * @param name
     * @return void
     * @author 魏荣杰
     * @date 2019/8/5 11:36
     * @since v1.0
     */
    void dataConsistencyUpdateWarehouse(String corpid, Long dataId, String name) throws XbbException;

    /**
     * 根据业务规则，更新出库单
     * @author 吴峰
     * @date 2019/8/19 16:29
     * @param outstockUpdateByBusinessRuleDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void updateBatchByBusinessRule(OutstockUpdateByBusinessRuleDTO outstockUpdateByBusinessRuleDTO) throws XbbException;

    /**
     * 汇总入库单产品信息（详情页，几种产品几件）
     *
     * @param businessProductListDTO 入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-28 10:23
     */
    ProductSummaryVO summaryProductList(BusinessProductListDTO businessProductListDTO) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, Boolean forProcess, Integer operate, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    void formatProduct4Show3(Map<String, Double> productBatchWarehouseMap, Map<String, Double> productWarehouseMap, Map<Long, String> warehouseNameMap, List<OutstockProductEntity> outstockProductEntityList, JSONObject data, UpdateDataTypeEnum updateDataTypeEnum, Integer type, Map<Long, List<MultiUnitPricePoJo>> priceMap) throws XbbException;

    PagingProductVO getPagingProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    /**
     * 解析单个产品
     * @param entity
     * @return
     */
    JSONObject formatSingleProduct(OutstockProductEntity entity);

    PagingProductVO getPagingProductionMaterielOutstockProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    PagingProductVO getPagingContractOutstockProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    JSONObject formatSingleContractOutstockProduct(OutstockProductEntity entity);

    JSONObject formatSingleProductionMaterielOutstockProduct(OutstockProductEntity entity);

    /**
     *
     * 自动生成其他出库单
     * @param saasFormSaveDTO 数据
     * @author jyh
     * @date 2020/1/19 10:30
     * @since v1.0
     *
     */
    void generateOutStockSheet(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    /**
     * 出库单上游单据删除，查询是否有下游出库单
     * @param corpid 公司id
     * @param idIn 出库单上游单据id，例如合同
     * @param type 出库单类型
     * @return 有下游单据的上游单据id
     */
    List<Long> hasDownstreamList(String corpid, List<Long> idIn, int type) throws XbbException;

    void formatBatchExplain(List<FieldAttrEntity> fieldAttrEntityList, String enable);

    /**
     * Description:  客户名称 同步销售出库单
     * @param corpid	公司id
     * @param customerId	客户id
     * @param customerName	  客户名称
     * @return  viod
     * @author wujian
     * @date
     * @since v1.0
     */
    void dataConsistemcyUpdateCustomerName(String corpid, Long customerId, String customerName);

    /**
     * 一致性同步
     * @param corpid 公司ID
     * @param contractId 合同id
     * @param serialNo 合同编号
     * @throws XbbException
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    void dataConsistencyUpdateContract(String corpid, Long contractId, String serialNo) throws XbbException;
    /**
     * 供应商名称一致性同步
     * @param corpid 公司ID
     * @param supplierId 供应商id
     * @param supplierName 供应商名称
     * @throws XbbException
     * @since v1.0
     * @version v1.0
     */
    void dataConsistencyUpdateSupplier(String corpid, Long supplierId, String supplierName) throws XbbException;

    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;
}
